package com.ken.elmssm.converter;

import com.ken.elmssm.bean.Role;
import com.ken.elmssm.common.ElmException;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ken
 */
@Component("RoleStringListConverter")
public class RoleStringListConverter implements Converter<String, List<Role>> {

    @Override
    public List<Role> convert(String source) {
        if(source != null) {
            List<Role> list = new ArrayList<>();
            try {
                list.add(new Role(Integer.valueOf(source),null));
            } catch (RuntimeException e) {
                throw new ElmException("角色ID转换异常");
            }
            return list;
        }
        return null;
    }
}
